/*
 * JasperReports - Free Java Reporting Library.
 * Copyright (C) 2001 - 2011 Jaspersoft Corporation. All rights reserved.
 * http://www.jaspersoft.com
 *
 * Unless you have purchased a commercial license agreement from Jaspersoft,
 * the following license terms apply:
 *
 * This program is part of JasperReports.
 *
 * JasperReports is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JasperReports is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
 */

import java.net.MalformedURLException;
import java.net.URL;


import javax.swing.JOptionPane;

import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JRViewer;

public class JRViewerApplet extends javax.swing.JApplet {




	/*
	 * edit $JRE_HOME/lib/security/java.policy
	 * 
	 * grant { permission java.security.AllPermission; };
	 */

	private static final long serialVersionUID = -4822093157016234460L;

	private URL url;

	private JasperPrint jasperPrint;

	private void loadReport() {
		try {
			jasperPrint = (JasperPrint) JRLoader.loadObject(url);
		} catch (Exception e) {
			e.printStackTrace();
			JOptionPane
					.showMessageDialog(this, "Load Error! " + e.getMessage());
		}
		if (jasperPrint != null) {
			JRViewer viewer = new JRViewer(jasperPrint);
			viewer.setSize(JRViewerApplet.this.getSize());
			JRViewerApplet.this.setContentPane(viewer);
//			JasperViewer.viewReport(jasperPrint);
		} else {
			JOptionPane.showMessageDialog(this, "Report Empty!");
		}
	}

	public void init() {
		try {
			url = new URL(getCodeBase(),
					"../servlets/jasperprint?sessionReport="
							+ getParameter("sessionReport"));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		loadReport();
	}

}
